/****

    activequant - activestocks.eu

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License along
    with this program; if not, write to the Free Software Foundation, Inc.,
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

	
	contact  : contact@activestocks.eu
    homepage : http://www.activestocks.eu

****/
package org.activequant.core.domainmodel.data;

import java.io.Serializable;

import org.activequant.core.domainmodel.InstrumentSpecification;
import org.activequant.core.types.TimeStamp;


/**
 * 
 * Market entity, base class for candle, quote and trade indication<br>
 * An abstract class (with an abstract <code>clone()</code> method). Holds the following associated variables:
 * <ul>
 * <li>id(Long)</li>
 * <li>instrumentSpecification(InstrumentSpecification)</li>
 * <li>timeStamp(TimeStamp)</li>
 * <li>receivedTimeStamp(TimeStamp)</li>
 * </ul>
 * <br>
 * <b>History:</b><br>
 *  - [12.10.2007] Created (Ulrich Staudinger)<br>
 *  - [01.11.2007] Added constructor, abstract class (Erik Nijkamp)<br>
 *  - [25.01.2008] Added Comparable<T> interface (Erik Nijkamp)<br>
 *  - [22.11.2009] Received timestamp added (Ulrich Staudinger)<br>
 *
 *  @author Ulrich Staudinger
 */
public abstract class MarketDataEntity<T extends MarketDataEntity<T>> implements Comparable<T>, Serializable {
	/**
	 * public static final int NOT_SET = -1;
	 */
	public static final int NOT_SET = -1;
	
	/**
	 * private Long id = null;<br/>
	 * id of this market entity.
	 */
	private Long id = null;

	/**
	 * private InstrumentSpecification instrumentSpecification;<br/>
	 * the specification for this market entity.
	 */
	private InstrumentSpecification instrumentSpecification;
	
	/**
	 * private TimeStamp timeStamp = new TimeStamp();<br/>
	 * the date of this market entity. 
	 */
	private TimeStamp timeStamp = new TimeStamp();
	/**
	 * private TimeStamp receivedTimeStamp = new TimeStamp();
	 */
	private TimeStamp receivedTimeStamp = new TimeStamp();
	
	public abstract T clone();
	/**
	 * empty constructor
	 */
	public MarketDataEntity() {
	}
	/**
	 * constructs a MarketDataEntity using the given date(TimeStamp) to set its associated timeStamp(TimeStamp)
	 * @param date
	 */
	public MarketDataEntity(TimeStamp date) {
		this.timeStamp = date;
	}
	/**
	 * constructs a MarketDataEntity using the given instrumentSpecification(InstrumentSpecification) to set its associated instrumentSpecification(InstrumentSpecification)
	 * @param instrumentSpecification
	 */
	public MarketDataEntity(InstrumentSpecification instrumentSpecification) {
		this.instrumentSpecification = instrumentSpecification;
	}
	/**
	 * constructs a MarketDataEntity using the given instrumentSpecification(InstrumentSpecification) and date(TimeStamp) to set its associated 
	 * instrumentSpecification(InstrumentSpecification) and timeStamp(TimeStamp)
	 * @param instrumentSpecification
	 * @param date
	 */
	public MarketDataEntity(InstrumentSpecification instrumentSpecification, TimeStamp date) {
		this.instrumentSpecification = instrumentSpecification;
		this.timeStamp = date;
	}
	
	/**
	 * returns the associated instrumentSpecification(InstrumentSpecification)
	 * @return
	 */
	public InstrumentSpecification getInstrumentSpecification() {
		return instrumentSpecification;
	}
	/**
	 * sets the associated instrumentSpecification(InstrumentSpecification) with the given instrumentSpecification(InstrumentSpecification)
	 * @param instrumentSpecification
	 */
	public void setInstrumentSpecification(InstrumentSpecification instrumentSpecification) {
		this.instrumentSpecification = instrumentSpecification;
	}

	/**
	 * TimeStamp when this event hits the market.
	 * <em>IMPORTANT</em> for Candles it corresponds to the <em>close</em>
	 * time, so that Candle accumulates events up to the time stamp.<br/>
	 * returns the associated timeStamp(TimeStamp)
	 * @return event time stamp.
	 */
	public TimeStamp getTimeStamp() {
		return timeStamp;
	}

	/**
	 * Sets event time stamp.<br/>
	 * sets the associated timeStamp(TimeStamp) with the given stamp(TimeStamp)
	 * @param stamp time stamp.
	 */
	public void setTimeStamp(TimeStamp stamp) {
		this.timeStamp = stamp;
	} 
	/**
	 * returns whether the associated id(Long) is not <code>null</code>
	 * @return
	 */
	public boolean hasId() {
		return id != null;
	}
	/**
	 * returns the associated id(Long)
	 * @return
	 */
	public Long getId() {
		return id;
	}
	/**
	 * sets the associated id(Long) with the given id(Long)
	 * @param id
	 */
	public void setId(Long id) {
		this.id = id;
	}

	/**
	 * The received timestamp should be set by the <T>Receiver upon reception. 
	 * The usual timestamps should be "official" timestamps, for example 
	 * timestamps as they are assigned by the exchange. <br/>
	 * returns the the associated receivedTimeStamps(TimeStamp)
	 * @return
	 */
	public TimeStamp getReceivedTimeStamp() {
		return receivedTimeStamp;
	}
	/**
	 * sets the associated receivedTimeStamps(TimeStamp) with the given receivedTimeStamps(TimeStamp)
	 * @param receivedTimeStamps
	 */
	public void setReceivedTimeStamp(TimeStamp receivedTimeStamps) {
		this.receivedTimeStamp = receivedTimeStamps;
	}	
}
